home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Clipboard / ScrapItem.cp < prev    next >
Text File  |  2000-06-23  |  982b  |  50 lines

  1. // ScrapItem.cp
  2.  
  3. #ifndef ScrapItem_h
  4. #include "ScrapItem.h"
  5. #endif
  6. #ifndef OSError_h
  7. #include "OSError.h"
  8. #endif
  9. #ifndef MasterPointer_h
  10. #include "MasterPointer.h"
  11. #endif
  12.  
  13. #include <Scrap.h>
  14. #include <Errors.h>
  15.  
  16. ScrapItem::ScrapItem( const ScrapType& theType )
  17.   : type( theType )
  18.   {
  19.     int32 result = GetScrap( 0, type.Value(), &offset );
  20.  
  21.     if ( result < 0 && result != noTypeErr )
  22.         throw OSError( result );
  23.  
  24.     exists = ( result != noTypeErr );
  25.     size = exists ? result : 0;
  26.   }
  27.  
  28. void ScrapItem::operator>>( MasterPointer& destination ) const
  29.   {
  30.     Assert( exists );
  31.     
  32.     // Resize the handle myself, since I know the size
  33.     // and SetSize has good error reporting.
  34.     
  35.     if ( destination.IsEmpty() )
  36.         destination.Allocate( size );
  37.      else
  38.         destination.SetSize( size );
  39.     
  40.     int32 ignoredOffset;
  41.     int32 result = GetScrap( destination.Handle(), type.Value(), &ignoredOffset );
  42.     
  43.     Assert( result != noTypeErr );
  44.     
  45.     if ( result < 0 )
  46.         throw OSError( result );
  47.     
  48.     Assert( result == size );
  49.   }
  50.